#pragma once

#ifndef NULL
#define NULL 0x0
#endif

class MemoryShare abstract;

class MemoryColector abstract
{
	friend MemoryShare;
protected:
	virtual void LiberarMemoria() abstract;
};

class MemoryShare abstract
{
public:
	virtual ~MemoryShare();

	static void CheckMemoryReleased();

private:
	struct MemColector
	{
		MemoryColector* Colector;
		const char* TypeName;
		MemColector* Next;
	};

	struct MemoryUsage
	{
		unsigned int Contador;
		MemColector* Colectors;
		MemoryUsage* NextUsage;
	};

	MemoryUsage* m_Used;

	void IncrementarContador() const;
	void DecrementarContador();
	void LiberarMemoria();

	static void RemoveFromGeneralUse(MemoryUsage* usage, MemoryUsage* &list);
	static void AddToGeneralUse(MemoryUsage* usage);
	static MemoryUsage* s_GeneralUse;

protected:
	MemoryShare();
	MemoryShare(const MemoryShare& m);
	MemoryShare& operator=(const MemoryShare& m);

	void ReservarMemoria(MemoryColector* colector, const char* typeName);
};
